package com.test.demo.main.adapter;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.test.demo.R;
import com.test.demo.bean.Comment;

import java.util.ArrayList;
import java.util.List;

/** 评论适配器 */
public class CommentAdapter extends BaseQuickAdapter<Comment, BaseViewHolder> {

    ArrayList<Comment> datas = new ArrayList<>();

    public CommentAdapter(ArrayList<Comment> data) {
        super(R.layout.adapter_comment, data);
    }

    public void setData(ArrayList<Comment> datas) {
        this.datas = datas;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, Comment repostBean) {
        baseViewHolder.setText(R.id.profile_name, repostBean.name);
        baseViewHolder.setText(R.id.tv_time_ago, repostBean.time);
        baseViewHolder.setText(R.id.tv_content, repostBean.content);
        baseViewHolder.setVisible(R.id.iv_hot, repostBean.isHot);
        if (repostBean.ivId != 0) {
            baseViewHolder.setImageResource(R.id.iv_comment, repostBean.ivId);
        }

        if (repostBean.circleId != 0) {
            baseViewHolder.setImageResource(R.id.profile_circle, repostBean.circleId);
        }

        RecyclerView recyclerView = baseViewHolder.getView(R.id.child_recyclerview);
        ReviewChildAdapter reviewChildAdapter = new ReviewChildAdapter();
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(reviewChildAdapter);
        List<String> stringList = new ArrayList<>();
        stringList.add("");
        stringList.add("");
        stringList.add("");
        reviewChildAdapter.setList(stringList);
        reviewChildAdapter.setOnItemChildClickListener((adapter, view, position) -> {
            if (onLongListener != null) {
                onLongListener.onItemClick();
            }
        });
    }

    OnItemListener onLongListener;

    public interface OnItemListener {
        void onItemClick();
    }

    public void setOnItemListener(OnItemListener onLongListener) {
        this.onLongListener = onLongListener;
    }


}
